import socket
def get_host_ip():
	try:
		s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
		s.connect(('8.8.8.8',80))
		ip = s.getsockname()[0]
	except:
		ip = '127.0.0.1'
		s=None
	finally:
		if s:
			s.close()
	return ip

options = {
	"port": 8000,
	"ip": get_host_ip()
}

import os
import platform
BASE_DIRS = os.path.dirname(__file__)
_Dir = BASE_DIRS.replace('\\','/').split('/')[0][0]	# 根目录


appconfig = {}
if platform.system() == 'Linux':
	appconfig["database_path"] = "/mnt/%s/database.db"%BASE_DIRS.replace(':','').replace('\\','/')
	appconfig['video_path'] = r'/mnt/%s/$RECYCLE.BIN/data'%_Dir.lower()
else:
	appconfig["database_path"] = os.path.join(BASE_DIRS,"database.db")
	appconfig['video_path'] = r'%s:/$RECYCLE.BIN/data'%_Dir
	if not os.path.exists(appconfig['video_path']):
		print('目录不存在: %s:/.../%s，切换目录：\\\Yoga710\d...' % (_Dir, appconfig['video_path'].split('/')[-1]))
		appconfig['video_path'] = r'\\Yoga710\d\$RECYCLE.BIN\data'
appconfig['image_path'] = appconfig['video_path'] + '/Images'

if not os.path.exists(appconfig['video_path']):
	print('目录不存在: %s:/.../%s'%(_Dir,appconfig['video_path'].split('/')[-1]))
	exit()

settings = {
	"static_path":os.path.join(BASE_DIRS,"static"),  #静态文件
	"template_path":os.path.join(BASE_DIRS,"templates"),  #视图
	"appconfig":appconfig,	# 自定义变量
	"debug":False ,	#修改完文件后服务自动启动
	"autoescape":None, #关闭自动转义
	"cookie_secret":"OrGWKG+lTja4QD6jkt0YQJtk+yIUe0VTiy1KaGBIuks",  #混淆加密
	"xsrf_cookies":False,  #开启xsrf保护
	"login_url":"/login"
}

appconfig['playerpath'] = settings['template_path']+'/player'